<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<jsp:include page="../header.jsp" />
<script>
	$(function() {
		$(document).ready(
				function() {
					var autorlist = '${book.autorIds}'
					for ( var i in autorlist) {
						$j("#autorIds option:eq(" + i + ")").attr("selected",
								"selected");
					}
				});
		$j("#oddeleniId option:eq(${oddeleniId})").attr("selected", "selected");
		$j("#nakladatelstviId option:eq(${nakladatelstviId})").attr("selected",
				"selected");
	});
</script>
<div id="content">
	<div id="topstory" class="box">
		<h1>
			<fmt:message key="book.title.edit" />
		</h1>
	</div>
	<div class="padding">
		<c:choose>
			<c:when test="${ book != null}">
				<form:form action="submit.do?bookId=${book.id}" commandName="book" method="POST">
					<table border="0" cellspacing="5" cellpadding="0" width="100%" class="formTable tplBorder">
						<tr>
							<td width="15%"></td>
							<td width="35%"></td>
							<td width="15%"></td>
							<td width="35%"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="books.name" /></td>
							<td><form:input path="nazev" /><form:errors path="nazev" cssStyle="color: red;"/></td>
							<td colspan="2"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="books.pocet" /></td>
							<td><form:input path="pocetKnih" /><form:errors path="pocetKnih" cssStyle="color: red;"/></td>
							<td colspan="2"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="books.rok" /></td>
							<td><form:input path="rokVydani" /><form:errors path="rokVydani" cssStyle="color: red;"/></td>
							<td colspan="2"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="books.nakladatelstvi" /></td>
							<td><form:select items="${book.nakladatelstviList }" itemLabel="nazev" itemValue="id" path="nakladatelstviId" /><form:errors path="nakladatelstviId" cssStyle="color: red;"/></td>
							<td colspan="2"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="books.author" /></td>
							<td><form:select items="${book.autorList }" multiple="true" itemLabel="label" itemValue="id" path="autorIds" /><form:errors path="autorIds" cssStyle="color: red;"/></td>
							<td colspan="2"></td>
						</tr>
						<tr>
							<td class="label"><fmt:message key="books.department" /></td>
							<td><form:select items="${book.oddeleniList }" itemLabel="nazev" itemValue="id" path="oddeleniId" /><form:errors path="oddeleniId" cssStyle="color: red;"/></td>
							<td colspan="2"></td>
						</tr>
						<tr>
							<td><input type="submit"/></td>
							<td></td>
							<td><input type="button" onclick="javascript:window.location = '../books.do'" value="Cancel"/></td>
							<td></td>
						</tr>
					</table>
				</form:form>
			</c:when>
			<c:otherwise>
				<h3>${error }</h3>
			</c:otherwise>
		</c:choose>
	</div>
	<!-- /padding -->
</div>
<!-- /content -->
<jsp:include page="side-menu.jsp" />
<jsp:include page="../foother.jsp" />
